package com.itboye.hutouben.activity.login;

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.view.View;
import android.widget.Button;

import com.itboye.hutouben.MainActivity;
import com.itboye.hutouben.R;
import com.itboye.hutouben.base.BaseActivity;


/**
 * 启动页
 */
public class SplashActivity extends BaseActivity {
	Button button2;
	private MyCountDownTimer mc;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);
		setStatusBarColor(R.color.main_color_two);
		button2 = (Button) findViewById(R.id.button2);
		onRun();
		/***
		 * 设置广告时长
		 */
		mc = new MyCountDownTimer(3000, 1000);
		mc.start();
		button2.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				startActivity(new Intent(SplashActivity.this, MainActivity.class));
				SplashActivity.this.finish();
				handler.removeMessages(0);
			}
		});


	}

	@Override
	protected void onInit() {

	}

	@Override
	protected void onReadIntent(Bundle bundle) {

	}

	public void onRun() {
		handler.postDelayed(new Runnable() {
			@Override
			public void run() {
//                SharedPreferences setting = getSharedPreferences("document", 0);
//                Boolean user_first = setting.getBoolean("FIRST", true);
//                if (user_first) {// 第一次
//                    Intent intent = new Intent(StartUpActivity.this, ActivityDiaoCha.class);
//                    startActivity(intent);
//                    setting.edit().putBoolean("FIRST", false).commit();
//                    StartUpActivity.this.finish();
//                } else {
				startActivity(new Intent(SplashActivity.this, MainActivity.class));
				SplashActivity.this.finish();
//                }
			}
		}, 3000);
	}
	private Handler handler = new Handler();

	class MyCountDownTimer extends CountDownTimer {
		/**
		 * @param millisInFuture    表示以毫秒为单位 倒计时的总数
		 *                          <p>
		 *                          例如 millisInFuture=1000 表示1秒
		 * @param countDownInterval 表示 间隔 多少微秒 调用一次 onTick 方法
		 *                          <p>
		 *                          例如: countDownInterval =1000 ; 表示每1000毫秒调用一次onTick()
		 */
		public MyCountDownTimer(long millisInFuture, long countDownInterval) {
			super(millisInFuture, countDownInterval);
		}
		public void onFinish() {
			button2.setText("正在跳转");
		}
		public void onTick(long millisUntilFinished) {
			button2.setText(millisUntilFinished / 1000 + "秒跳过");
		}
	}
	@Override
	public void onClick(View v) {

	}
}
